package com.schedualnew.mq.controller;


import com.schedualnew.mq.dto.common.Res;
import com.schedualnew.mq.dto.exam.DictPrintPatternDto;
import com.schedualnew.mq.dto.exam.schedule.QueryScheduledAppliesDto;
import com.schedualnew.mq.dto.exam.schedule.QueryScheduledApplyDto;
import com.schedualnew.mq.dto.exam.schedule.ScheduledExamApplyInfoDto;
import com.schedualnew.mq.service.ScheduleServiceImpl;
import com.schedualnew.mq.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.javassist.runtime.DotClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/schedule/public")
public class PublicController {
    @Autowired
    private ScheduleServiceImpl examApplyService;

    @PostMapping({"/schedule/print"})
    public Res print(@RequestBody QueryScheduledApplyDto dto) {
        // 获取最近预约的申请单列表
        List<DictPrintPatternDto> print = examApplyService.getScheduledList(dto);
        return Res.Success(print);
    }


    @PostMapping({"/schedule/now_print"})
    public Res now_print(@RequestBody QueryScheduledApplyDto dto) {
        // 根据预约日期查询申请单列表
        List<DictPrintPatternDto> print = examApplyService.getScheduledListByDate(dto);
        return Res.Success(print);
    }

    /**
     * 查询患者超声可报道的申请单列表，当日
     *
     * @param dto
     * @return
     */
    @PostMapping({"/schedule/queryUltrasoundApplies"})
    public Res queryApplies(@RequestBody QueryScheduledAppliesDto dto) {
        if (StringUtils.isBlank(dto.getSickId())) {
            return Res.Fail("患者id不能为空!");
        }
        // 获取最近预约的申请单列表
        dto.setScheduleDate(DateUtils.getCurrDate());
        if (StringUtils.isBlank(dto.getExamClass())) {
            dto.setExamClass("超声");
        }
        List<ScheduledExamApplyInfoDto> infoDtos = examApplyService.queryScheduleApplies(dto);
        return Res.Success(infoDtos);
    }
}
